package com.xmkj.bearbiz.count;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.common.mvp.BaseMvpActivity;
import com.common.mvp.BasePresenter;
import com.common.retrofit.methods.FirstSetPswMethods;
import com.common.retrofit.subscriber.CommonSubscriber;
import com.common.retrofit.subscriber.SubscriberListener;
import com.common.utils.EmptyUtils;
import com.xmkj.bearbiz.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by chen on 2018/4/5.
 */

public class setPswActivity extends BaseMvpActivity {
    public static final String SMSCODE = "smscode";
    public static final String MOBILE = "mobile";
    public static final String UID = "uid";
    @BindView(R.id.et_psw)
    EditText mEtPsw;
    @BindView(R.id.et_psw_again)
    EditText mEtPswAgain;
    @BindView(R.id.tv_finnsh)
    TextView mTvFinnsh;
    private String mCode;
    private String mMobile;
    private String mMUid = "";

    @Override
    protected BasePresenter createPresenterInstance() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_set_psw;
    }

    @Override
    protected void onViewCreated() {
        mCode = getIntent().getStringExtra(SMSCODE);
        mMobile = getIntent().getStringExtra(MOBILE);
        mMUid = getIntent().getStringExtra(UID);
        
    }

    @Override
    protected void doLogicFunc() {
        attachClickListener(mTvFinnsh);
    }

    @Override
    protected void onViewClicked(View view) {
        if(view.getId()==mTvFinnsh.getId()){
            if(EmptyUtils.isEmpty(getEditTextStr(mEtPsw))||EmptyUtils.isEmpty(getEditTextStr(mEtPswAgain))){
                showToastMsg("请填写密码");
                return;
            }else if(!getEditTextStr(mEtPsw).equals(getEditTextStr(mEtPswAgain))){
                showToastMsg("两次密码输入不一样");
                mEtPsw.setText("");
                mEtPswAgain.setText("");
                return;
            } else {
                gotoHttp();
            }
        }
    }

    private void gotoHttp() {
        showProgressingDialog();
        CommonSubscriber<Object> subscriber = new CommonSubscriber<>(new SubscriberListener() {
            @Override
            public void onNext(Object o) {

                dismissProgressDialog();
                finish();
                gotoActivity(LoginActivtiy.class);
            }

            @Override
            public void onError(String e, int code) {
                dismissProgressDialog();
                showToastMsg(e);
            }
        });


        FirstSetPswMethods.getInstance().mobileRegister(subscriber,mMobile,getEditTextStr(mEtPsw),getEditTextStr(mEtPswAgain),mCode);
        rxManager.add(subscriber);
    }

    @Override
    protected void setNavigation() {
        setNavigationBack("设置密码");
    }


    @Override
    public void bindKnife() {
        ButterKnife.bind(this);
    }
}
